// pages/pressure-test-list/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    param: {
      page: 1,
      pageSize: 10,
      status: "all",
    },
    isMerchantEmp: false,
    hasMore: true,
    type: "",
    merchant_id: "",
  },

  handleGetMore() {
    const { hasMore, param } = this.data;

    if (hasMore) {
      param.page++;

      this.setData({
        param,
      });

      this.getData();
    }
  },

  handleDonePressureTest(event) {
    const { item } = event.currentTarget.dataset;
    wx.navigateTo({
      url: "/pages/pressure-test-done/index?data=" + JSON.stringify(item),
    });
  },
  handlePressureApply(event) {
    //上传资源,可支撑图片、视频、VR视频
    const { item } = event.currentTarget.dataset;
    const id = item.id;
    const type = item.type;
    wx.navigateTo({
        url: "/pages/pressure-apply-file/pressure-apply-file?infoId=" + id,
      });
  },
  handleDonePressureTestImg(event) {
    const { item } = event.currentTarget.dataset;
    const id = item.id;
    const type = item.type;
    wx.navigateTo({
      url: "/vr/pages/upload-file-vr/uploadFileVR?infoId=" + id+"&findVrType="+type,
    });
  },
  handleDonePressureTestVideo(event) {
    const { item } = event.currentTarget.dataset;
    const id = item.id;
    const type = item.type;
    wx.navigateTo({
      url: "/vr/pages/upload-file-vr/uploadFileVR?infoId=" + id+"&findVrType="+type,
    });
  },
  handleDonePressureTestVr(event) {
    const { item } = event.currentTarget.dataset;
    const id = item.id;
    const type = item.type;
    wx.navigateTo({
      url: "/vr/pages/upload-file-vr/uploadFileVR?infoId=" + id+"&findVrType="+type,
    });
  },
  handleDonePressureTestVrInfo(event) {
    const { item } = event.currentTarget.dataset;
    const id = item.id;
    const type = item.type;
    wx.navigateTo({
      url: "/vr/pages/vr-preview/vr-preview?infoId=" + id+"&findVrType="+type,
    });
  },
  getData() {
    const { type, param, merchant_id } = this.data;

    if (param.status == "1") {
      param.status = "1";
    } else {
      delete param.status;
    }

    const params = {
      ...param,
      merchant_id,
    };

    wx.ajax
      .post(
        type === "5"
          ? "queryPageSDGPressureApply.action"
          : "queryPageJXDLPressureApply.action",
        params,
        true
      )
      .then((res) => {
        // console.log(res);
        if (res.success) {
          const oriList = this.data.list;

          const result = res.result;

          this.setData({
            list: oriList.concat(result.pageList || []),
            hasMore: result.totalPages > result.page,
          });
        }
      });
  },
  handleToPage1(event) {
    const { id, item, agentid } = event.currentTarget.dataset;

    wx.navigateTo({
      url: `/pages/pressure-test-submit-detail/index?id=${id}&agentid=${agentid}&data=${JSON.stringify(
        item
      )}`,
    });
  },

  handleTabClick(event) {
    const { value } = event.currentTarget.dataset;

    const { param } = this.data;

    param.page = 1;
    param.status = value;

    this.setData({
      param,
      list: [],
    });

    this.getData();
  },

  handleToPage(event) {
    const { id } = event.currentTarget.dataset;

    wx.navigateTo({
      url: `/pages/pressure-test-submit/index?id=${id}`,
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.type && options.type === "5") {
      // 水电工 合作门店 跳转过来
      this.setData({
        type: options.type,
      });
    }

    this.setData({
      merchant_id: options.id,
      isMerchantEmp: options.isMerchantEmp === "1",
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      list: [],
    });
    this.getData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
});
